<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>任务订单列表</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<!-- Add by Kravis Liu 2014.09.22 -->
		<link rel="stylesheet" href="/css/base.css" />
		<link rel="stylesheet" href="/css/list2.css" />
		<script src="/js/jquery-1.11.1.min.js"></script>
		<script type="text/javascript">
		
			function updateOrderStatus(orderId,status){
				var statusText = "";
				if(status == 1){
					statusText = "已完成";
					if(confirm("是否修改订单为已完成?")){

						$.ajax({
						   type: "POST",
						   url: "/app/updateOrderStatus",
						   data: "orderId="+orderId + "&status=" + status,
						   success: function(msg){					 
							 if(msg == "success"){						 
								$("#" + orderId).find("div[name='orderStatus']").text(statusText);
								$("#" + orderId).find("a[name='over']").hide();						
							 } else {
								alert( msg );
							 }					 
						   }
						});				
					}					
				} else if (status == 2){
					statusText = "取消";
					if(confirm("是否取消订单为？")){

						$.ajax({
						   type: "POST",
						   url: "/app/updateOrderStatus",
						   data: "orderId="+orderId + "&status=" + status,
						   success: function(msg){					 
							 if(msg == "success"){						
								$("#" + orderId).find("div[name='orderStatus']").text(statusText);
								$("#" + orderId).find("a[name='cancel']").hide();
								$("#" + orderId).find("a[name='over']").hide();									
							 } else {
								alert( msg );
							 }					 
						   }
						});				
					}					
				}


			}
			
			function deleteOrder(orderId){
				if(confirm("是否删除订单？")){
					$.ajax({
					   type: "POST",
					   url: "/app/deleteOrder",
					   data: "orderId="+orderId,
					   success: function(msg){
						 
						 if(msg == "success"){						
							$("#"+orderId).hide();
						 } else {
							alert( msg );
						 }
						 
					   }
					});				
				}

			}
			function examineOrder(orderId){
				$.ajax({
				   type: "POST",
				   url: "/app/examineOrder",
				   data: "orderId="+orderId,
				   success: function(msg){
					 
				   }
				});				
			}
		</script>
	</head>
	<body>
		<div id="page">
			<div id="header">
				<h4>后台管理</h4>
			</div>

			<table width="98%" align="center" border="1" cellpadding="0" cellspacing="0">
				<tbody id="add_point">
					<tr>
						<td><div align="center">订单号</div></td>
						<td><div align="center">所属任务</div></td>						
						<td><div align="center">下单用户</div></td>
						<td><div align="center">订单状态</div></td>
						<td><div align="center">操作</div></td>
					</tr>
					<% if (Orders){ %>
					<%  Orders.forEach(function (order){ %>	
					<tr id="<%= order.id%>">
						<td><div align="center"><%= order.id%></div></td>
						<% if(order.get('taskObject')){%>
							<td><div align="center"><%= order.get('taskObject').get('taskTitle') %></div></td>
						<%}%>
						<% if(order.get('userObject')){%>
							<td><div align="center"><%= order.get('userObject').get('username') %></div></td>
						<%}%>
						
						<%if (order.get('status') == "0"){%>
							<td><div align="center" name="orderStatus">待完成</div></td>
							<td><div align="center">
								<a name="over" href='javascript:void(0)' onClick='updateOrderStatus("<%= order.id%>",1);' >完成订单</a>
								<a name="cancel" href='javascript:void(0)' onClick='updateOrderStatus("<%= order.id%>",2);' >取消订单</a>
								<a href='javascript:void(0)' onClick='deleteOrder("<%= order.id%>");'>删除订单</a>
							</div></td>
						<%} else if(order.get('status') == "1"){%>
							<td><div align="center" name='orderStatus'>已完成</div></td>
							<td><div align="center">
								<a name="cancel" href='javascript:void(0)' onClick='updateOrderStatus("<%= order.id%>",2);' >取消订单</a>
								<a href='javascript:void(0)' onClick='deleteOrder("<%= order.id%>");'>删除订单</a>
							</div></td>
						<%} else if(order.get('status') == "2"){%>
							<td><div align="center" name='orderStatus'>取消</div></td>
							<td><div align="center">
								<a href='javascript:void(0)' onClick='deleteOrder("<%= order.id%>");'>删除订单</a>
							</div></td>
						<%} else if(order.get('status') == "3"){%>
							<td><div align="center" name="orderStatus">待审核</div></td>
							<td><div align="center">
							<% if(order.get('orderImages')) {%>
								<a name="over" href='/app/examineOrder?orderId=<%= order.id%>'  >审核订单</a>	
							<%}%>								
								<a name="cancel" href='javascript:void(0)' onClick='updateOrderStatus("<%= order.id%>",2);' >取消订单</a>
								<a href='javascript:void(0)' onClick='deleteOrder("<%= order.id%>");'>删除订单</a>
							</div></td>							
						<%}%>
					</tr>
					<% })} %>  
				</tbody>
			</table>
			<p>&nbsp;</p>
			
			<div id="footer">
				<a style="float:right;margin:5px" href="/logout">退出</a>
				<a style="float:right;margin:5px" href="/app/index">主页</a>
				<% if(next != 0){ %>
					<a style="float:right;margin:5px" href="/app/orderList?taskId=<%= taskId %>&page=<%=next%>">下一页</a>
				<%}%>					
				<% if(previous >= 0){ %>
					<a style="float:right;margin:5px" href="/app/orderList?taskId=<%= taskId %>&page=<%=previous%>">上一页</a>
				<%}%>					
			</div>
		</div>
	</body>
</html>
